#include<iostream>
#include<cstring>
using namespace std;
class Account
{
private:
    static double count; // 账户总余额
    static double interestRate;
    string accno, accname;
    double balance;
public:
    Account(string ac, string na, double ba):accno(ac),accname(na),balance(ba)
    {
        count=count+balance;
    }
    ~Account(){}
    void deposit(double amount)
    {
        balance=balance+amount;
    }
    void withdraw(double amount)
    {
        balance=balance-amount;
        count=count-amount;
    }
    double getBalance()
    {
        return balance;
    }
    friend void update(Account& a)
    {
        double ans;
        ans=a.balance+a.balance*a.getInterestRate();
        a.balance=ans;
        count=count+a.balance;
        cout<<ans<<" ";
    }
    void show()
    {
        cout<<accno<<" "<<accname<<" ";
    }
    static double getCount()
    {
        return count;
    }
    static void setInterestRate(double rate)
    {
        interestRate=rate;
    }
    static double getInterestRate()
    {
        return interestRate;
    }
    Account(){ };
    void Init(string ac, string na, double ba)
    {
        accno=ac;
        accname=na;
        balance=ba;
    }
};
double Account::count=0;
double Account::interestRate=0;
int main()
{
    double setRate;
    cin>>setRate;
    Account::setInterestRate(setRate);
    int N;
    cin>>N;
    Account* num=new Account[N];
    int i=0;
    while(N--)
    {
        string nomer,name;
        double balance,cun,qu;
        cin>>nomer>>name>>balance>>cun>>qu;
        num[i].Init(nomer,name,balance);
        num[i].show();
        num[i].deposit(cun);
        cout<<num[i].getBalance()<<" ";
        update(num[i]);
        num[i].withdraw(qu);
        cout<<num[i].getBalance()<<endl;
        i++;
    }
    cout<<num[0].getCount()<<endl;
}